package com.itheima.exception;


import com.itheima.constant.Code;
import com.itheima.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e){
        Integer code = e.getCode();
        String message = e.getMessage();
        Result result=new Result(false,message,code);
        return result;
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
        Result result=new Result(false,e.getMessage(), Code.SYSTEM_ERROR);
        return result;
    }
}
